#pragma once

typedef unsigned int uint32;
typedef unsigned char uint8;

#define pinMode(x,y)  
#define OUTPUT 1
#define INPUT 0
#define HIGH 1
#define LOW 0
#define digitalWrite(x,y) 
#define digitalRead(x) x
#define delay(x)

class I2C
{
private:
	uint32 _SCL;
	uint32 _SDA;

protected:
	void Start()
	{
		digitalWrite(this->_SDA, HIGH);
		digitalWrite(this->_SCL, HIGH);
		digitalWrite(this->_SDA, LOW);
		digitalWrite(this->_SCL, LOW);
	};
	void End()
	{
		digitalWrite(this->_SCL, LOW);
		digitalWrite(this->_SDA, LOW);
		digitalWrite(this->_SCL, HIGH);
		digitalWrite(this->_SDA, HIGH);
	};

	void Ack()
	{
		digitalWrite(this->_SDA, LOW);
		digitalWrite(this->_SCL, HIGH);
		digitalWrite(this->_SCL, LOW);
	}

	void NoAck()
	{
		digitalWrite(this->_SDA, HIGH);
		digitalWrite(this->_SCL, HIGH);
		digitalWrite(this->_SCL, LOW);
	}

	bool SendByte(uint8 data);
	uint8 ReadByte(bool ACK);

public:
	I2C(uint32 SCL, uint32 SDA) : _SCL(SCL), _SDA(SDA) {};
	void Init()
	{
		pinMode(this->_SCL, OUTPUT);
		pinMode(this->_SDA, OUTPUT);
		digitalWrite(this->_SCL, HIGH);
		digitalWrite(this->_SDA, HIGH);
	};

	bool SendAddByte(uint8 addr, uint8 regaddr, uint8 data);
	bool ReadAddByte(uint8 addr, uint8 regaddr, uint8& data);

	bool SendAddArr(uint8 addr, uint8 regaddr, uint8* databuf, uint8 lenth);
	bool ReadAddArr(uint8 addr, uint8 regaddr, uint8* databuf, uint8 lenth);
};
